package com.zy;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

/**
 * @program: monitor147
 * @description:
 * @author: zy
 * @create: 2025-06-04 18:45
 */
public class MonitorCientChannelInitializer extends ChannelInitializer<Channel> {

    private final static int MAX_OBJECT_SIZE=1024*1024;

    @Override
    protected void initChannel(Channel channel) throws Exception {
        //在这里对channel进行实始化( 装配处理器 )
        ChannelPipeline pipeline= channel.pipeline();
        //对象解码器，它的作用是将接收到的ByteBuf解码为Java对象
        pipeline.addLast(     new ObjectDecoder(  MAX_OBJECT_SIZE, ClassResolvers.weakCachingConcurrentResolver( this.getClass().getClassLoader()   )     )      );
        pipeline.addLast(  new ObjectEncoder()  );

        pipeline.addLast(    new MonitorClientHandler());   //这个MonitorClientHandler类的功能 : 1. oshi获取本机的信息  2. 将这个信息序列化后，发给服务器

    }
}
